//
//  MqForumDetailTableViewCell.m
//  Meiqi
//
//  Created by lanou on 16/1/13.
//  Copyright © 2016年 KFC. All rights reserved.
//

#import "MqForumDetailTableViewCell.h"
#import <UIButton+WebCache.h>
#define kMartinGap 10
@implementation MqForumDetailTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        _avatarButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _avatarButton.frame  = CGRectMake(20, 10, 40, 40);
        _avatarButton.layer.cornerRadius = kScreenWidth / 20;
        _avatarButton.layer.masksToBounds = YES;
        [self.contentView addSubview:_avatarButton];
        
        _usernameLabel = [[UILabel alloc] initWithFrame:CGRectMake(_avatarButton.right + kMartinGap, _avatarButton.top , kScreenWidth / 3 * 2, 15)];
        [self.contentView addSubview:_usernameLabel];
        
        UILabel *creditLabel = [[UILabel alloc] initWithFrame:CGRectMake(_usernameLabel.left, _usernameLabel.bottom + 10, 30, _usernameLabel.height)];
        creditLabel.text = @"积分";
        creditLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:creditLabel];
        
        _creditsLabel = [[UILabel alloc] initWithFrame:CGRectMake(creditLabel.right, _usernameLabel.bottom + 10, 50, _usernameLabel.height)];
        _creditsLabel.textColor = [UIColor redColor];
        _creditsLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:_creditsLabel];
        
        UILabel *medalLabel = [[UILabel alloc] initWithFrame:CGRectMake(_creditsLabel.right, _creditsLabel.top, creditLabel.width, _creditsLabel.height)];
        medalLabel.font = [UIFont systemFontOfSize:12];
        medalLabel.text = @"徽章";
        [self.contentView addSubview:medalLabel];
        
        _medalsLabel = [[UILabel alloc] initWithFrame:CGRectMake(medalLabel.right + 10, _creditsLabel.top, _creditsLabel.width / 2, _creditsLabel.height)];
        _medalsLabel.textColor = [UIColor redColor];
        _medalsLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:_medalsLabel];
        
        _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(_medalsLabel.right , _medalsLabel.top, _medalsLabel.width * 4, _medalsLabel.height)];
        _timeLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:_timeLabel];
        
        
        _ownerLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth - 30, 0, 30, 20)];
//        _ownerLabel.text = @"";
        _ownerLabel.textAlignment = NSTextAlignmentCenter;
        _ownerLabel.font = [UIFont systemFontOfSize:12];
        _ownerLabel.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_ownerLabel];
        
        _commentButton  = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _commentButton.frame = CGRectMake(_usernameLabel.right + 20 , _ownerLabel.bottom + 5, 30, 8);
        [_commentButton setBackgroundImage:[UIImage imageNamed:@"btn_create_comment@2x"] forState:(UIControlStateNormal)];
        [self.contentView addSubview:_commentButton];
        
        _messageWebV = [[UIWebView alloc] initWithFrame:CGRectMake(_avatarButton.left, _avatarButton.bottom + 20, kScreenWidth - 20 * 2, 100)];
        
        //  关闭边缘滑动
        _messageWebV.scrollView.bounces = NO;
        _messageWebV.scrollView.alwaysBounceHorizontal = NO;
        _messageWebV.scrollView.alwaysBounceVertical = NO;
        
        //  滑动条
        _messageWebV.scrollView.showsHorizontalScrollIndicator = NO;
        _messageWebV.scrollView.showsVerticalScrollIndicator = NO;
        [self.contentView addSubview:_messageWebV];
        
    }
    
    return self;
    
}


- (void)setDetailModel:(MqForumDetailModel *)detailModel{
    
    _detailModel = detailModel;
    
    [_avatarButton sd_setBackgroundImageWithURL:[NSURL URLWithString:_detailModel.avatar] forState:(UIControlStateNormal)];
    _usernameLabel.text = detailModel.author;
    
    _creditsLabel.text = detailModel.credits;
    _medalsLabel.text = _detailModel.medals;
    _timeLabel.text = _detailModel.dateline;
    
    //  显示楼层位置
    if ([detailModel.position isEqualToString:@"1"]) {
        
        _ownerLabel.text = [NSString stringWithFormat:@"主楼"];
        
    }else{
        
        _ownerLabel.text = [NSString stringWithFormat:@"%@#",detailModel.position];
        
    }
    
       
}

////+ (CGFloat)heightForCellWithModel:(MqForumDetailModel *)model{
//
//    UIWebView *webView = [[UIWebView alloc] init];
//  
//    NSString *xmlString = model.message;
//    xmlString = [NSString stringWithFormat:@"<head><style>img{width:%fpx !important;}</style></head>%@",kScreenWidth - 40 ,xmlString];
//    for (NSString *img in model.imagelist) {
//        
//        NSDictionary *dic = model.picDic[img];
//        
//        NSString *attachment = dic[@"attachment"];
//        
//        NSString *attchicon = dic[@"attachicon"];
//        
//        //  拼接字符串
//        NSString *path = [NSString stringWithFormat:@"http://bbs.biketo.com/%@%@",dic[@"url"], attachment];
//        
//        NSString *str = [attchicon stringByReplacingOccurrencesOfString:@"static/image/filetype/image.gif" withString:path];
//        
//        xmlString = [xmlString stringByAppendingString:str];
//        
//    }
//    
//    //    NSLog(@"%@",xmlString);
//    [webView loadHTMLString:xmlString baseURL:nil];
//
//    webView.delegate = self;
//    
//}
//
//- (void)webViewDidFinishLoad:(UIWebView *)webView{
//    
//    CGFloat height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"] floatValue];
//    
//    NSLog(@"%f",height);
////    _tableView.rowHeight = height + webView.bottom;
//
//    
//    
//}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
